package edu.pku.sei.gefcommon.descriptor.descriptors;

import org.eclipse.jface.viewers.ICellEditorValidator;

class NumberValidator implements ICellEditorValidator {
	private ValidType type;
	public NumberValidator(ValidType t){
		type = t;
	}

	public String isValid(Object value) {
		if(type==ValidType.INTEGER){
			if(((String)value).matches("[-+]?[0-9]+"))
				return null;
			return "Invalid Integer Number";
		} else if(type==ValidType.DOUBLE) {
			if(((String)value).matches("([-+]?[0-9]+([.][0-9])?)|([0-9]?[.][0-9]+)"))
				return null;
			return "Invalid Double Number";
		}
		return "Invalid Number";
	}
	static public NumberValidator doubleValidator = new NumberValidator(ValidType.DOUBLE);
	static public NumberValidator integerValidator = new NumberValidator(ValidType.INTEGER);

}
